<?php
function view_alamat(){
	view_header_top();
	$id = $_SESSION['logged']['id'];
	$user = getUser($_SESSION['logged']['id']);
	//----------------------------------------------------------------
	$title = "Realita - ".$user['nama'];
	$content = "Realita ".$user['nama'];
	$url = PROFIL_URL."a/".$user['idFB'];
	$image = IMAGE_URL."300x240.gif";	//profpic orangnya / tokonya
	$desc = "Profil orangnya : ".$user['bio'];
	$auth = "RealiTA";
	$qwords = "profil, marketplace, umkm".$user['nama'];
	//----------------------
	echo "<title>$title</title>";
	//<!--META DATA Open Graph-->
	echo "<meta property=\"og:title\" content=\"$title\"/>";
	echo "<meta property=\"og:type\" content=\"$content\"/>";
	echo "<meta property=\"og:url\" content=\"$url\"/>";
	echo "<meta property=\"og:image\" content=\"$image\"/>";
	echo "<meta property=\"og:site_name\" content=\"RealiTA UMKM\"/>";
	echo "<meta property=\"og:description\" content=\"$desc\" />";
	//<!--META DATA FB-->
	echo "<meta property=\"fb:app_id\" content=\"147346958657510\" />";
	//<!--META DATA-->
	echo "<meta name=\"author\" content=\"$auth\" />";
	echo "<meta name=\"keywords\" content=\"$qwords\" />";
	echo "<meta name=\"description\" content=\"$desc\" />";
	echo "<meta name=\"robots\" content=\"ALL\" />";
	echo "<meta charset=\"UTF-8\" />";
	//----------------------------------------------------------------
?>
	<script type="text/javascript">
	//ongkir
	$(function() {
	//autocomplete untuk mencari kota asal
		$("#kota").autocomplete({
			minLength: 3,
			delay: 3,
			source: function(request, response) {
				$.ajax({
					url: "<?php echo HOME_URL ?>ongkir/kota",
					dataType: "json",
					data: {
						term : request.term,
						from : $('#kota').val(),
					},
					success: function(data) {
						response( $.map(data, function(item){
							return{
								label: item.nama_kota,
								value: item.nama_kota,
							}
						}));
					}
				});
			},
		});
	});
	</script>
<?php
	view_header_bottom();
?>
<!-- Content -->
	<div class="row">    
		<!-- Main Content Section -->
		<!-- This has been source ordered to come first in the markup (and on small devices) but to be to the right of the nav on larger screens -->
		<div class="large-9 push-3 columns">		  
		  <h3><?php echo $user['nama']; ?></h3>
		  <?php
		  if (isset($_SESSION['message'])) {
				echo "<div class='alert-box warning'>".$_SESSION['message']."<a href='#' class='close'>&times;</a></div>";
				unset($_SESSION['message']);
			}
		?>
		  <hr />
		  <h5>Daftar Alamat</h5>
		  <ul>
		  <?php
		  $alamats = getListAlamat($user['idPengguna']);
		  foreach ($alamats as $alamat){
			  echo "<li><a href=\"".PROFIL_URL."edit/alamat/".$alamat['idAlamat']."\">".
				$alamat['nama_penerima']." (".$alamat['no_kontak'].")"."</a><br />".
				$alamat['kota']."<br />".
				$alamat['lengkap'].	
				"</li>";
		  }
		  ?>
		  </ul>
		<h5><a href="javascript:bkttp('tambah_alamat');">Tambah Alamat</a></h5>
			<div id="tambah_alamat" style="display:none">
				<div class="row" style="display:block" id="isian">
					<form method="post" action="<?php echo PROFIL_URL."alamat" ?>">
					<input type="hidden" name="index" value="<?php echo $user['idPengguna'] ?>" />
					<div class="large-12 columns">
						<div class="row">
							<div class="large-6 columns">
								<label>Nama Penerima</label>
								<input type="text" name="nama" placeholder="Nama penerima..." />
							  </div>
						</div>
						<div class="row">
							<div class="large-3 columns">
								<label>Nomor Kontak</label>
								<input type="text" name="kontak" placeholder="Nomor kontak penerima..." />
							  </div>
						</div>
						<div class="row">
							<div class="large-4 columns">
								<label>Kota</label>
								<input id="kota" type="text" name="kota" placeholder="Nama kota..." />
							  </div>
						</div>
						<div class="row">
							<div class="large-12 columns">
								<label>Alamat Lengkap</label>
								<textarea name="alamat" placeholder="alamat lengkap penerima..."></textarea>
							  </div>
						</div>
						<div class="row">
							<div class="large-12 columns">
								<input class="button" type="submit" name="tambah-alamat" value="Tambah Alamat"/>
							  </div>
						</div>
					</div>
					</form>
				</div>
			</div>
		</div>
		<!-- Nav Sidebar -->
		<!-- This is source ordered to be pulled to the left on larger screens -->
		<?php view_tab($user); ?>
	  </div>
    <!-- End Content -->
<?php
	view_footer();
}

function edit_alamat($idalamat){
	view_header_top();
	$id = $_SESSION['logged']['id'];
	$user = getUser($_SESSION['logged']['id']);
	//----------------------------------------------------------------
	$title = "Realita - ".$user['nama'];
	$content = "Realita ".$user['nama'];
	$url = PROFIL_URL."a/".$user['idFB'];
	$image = IMAGE_URL."300x240.gif";	//profpic orangnya / tokonya
	$desc = "Profil orangnya : ".$user['bio'];
	$auth = "RealiTA";
	$qwords = "profil, marketplace, umkm".$user['nama'];
	//----------------------
	echo "<title>$title</title>";
	//<!--META DATA Open Graph-->
	echo "<meta property=\"og:title\" content=\"$title\"/>";
	echo "<meta property=\"og:type\" content=\"$content\"/>";
	echo "<meta property=\"og:url\" content=\"$url\"/>";
	echo "<meta property=\"og:image\" content=\"$image\"/>";
	echo "<meta property=\"og:site_name\" content=\"RealiTA UMKM\"/>";
	echo "<meta property=\"og:description\" content=\"$desc\" />";
	//<!--META DATA FB-->
	echo "<meta property=\"fb:app_id\" content=\"147346958657510\" />";
	//<!--META DATA-->
	echo "<meta name=\"author\" content=\"$auth\" />";
	echo "<meta name=\"keywords\" content=\"$qwords\" />";
	echo "<meta name=\"description\" content=\"$desc\" />";
	echo "<meta name=\"robots\" content=\"ALL\" />";
	echo "<meta charset=\"UTF-8\" />";
	//----------------------------------------------------------------
?>
	<script type="text/javascript">
	//ongkir
	$(function() {
	//autocomplete untuk mencari kota asal
		$("#kota").autocomplete({
			minLength: 3,
			delay: 3,
			source: function(request, response) {
				$.ajax({
					url: "<?php echo HOME_URL ?>ongkir/kota",
					dataType: "json",
					data: {
						term : request.term,
						from : $('#kota').val(),
					},
					success: function(data) {
						response( $.map(data, function(item){
							return{
								label: item.nama_kota,
								value: item.nama_kota,
							}
						}));
					}
				});
			},
		});
	});
	</script>
<?php
	view_header_bottom();
?>
<!-- Content -->
	<div class="row">    
		<!-- Main Content Section -->
		<!-- This has been source ordered to come first in the markup (and on small devices) but to be to the right of the nav on larger screens -->
		<div class="large-9 push-3 columns">		  
		  <h3><?php echo $user['nama']; ?></h3>
		  <?php
		  if (isset($_SESSION['message'])) {
				echo "<div class='alert-box warning'>".$_SESSION['message']."<a href='#' class='close'>&times;</a></div>";
				unset($_SESSION['message']);
			}
			$alamat = getAlamat($idalamat);
		?>
		<hr />
		<h3>Ubah Alamat</h3>
		<h5><a href="<?php echo PROFIL_URL ?>">[Hapus]</a></h5>
			<div class="row" style="display:block" id="isian">
				<form method="post" action="<?php echo PROFIL_URL."edit/alamat" ?>">
				<input type="hidden" name="index" value="<?php echo $idalamat ?>" />
				<div class="large-12 columns">
					<div class="row">
						<div class="large-6 columns">
							<label>Nama Penerima</label>
							<input type="text" name="nama" placeholder="Nama penerima..." value="<?php echo $alamat['nama_penerima'] ?>" />
						  </div>
					</div>
					<div class="row">
						<div class="large-3 columns">
							<label>Nomor Kontak</label>
							<input type="text" name="kontak" placeholder="Nomor kontak penerima..." value="<?php echo $alamat['no_kontak'] ?>" />
						  </div>
					</div>
					<div class="row">
						<div class="large-4 columns">
							<label>Kota</label>
							<input id="kota" type="text" name="kota" placeholder="Nama kota..." value="<?php echo $alamat['kota'] ?>" />
						  </div>
					</div>
					<div class="row">
						<div class="large-12 columns">
							<label>Alamat Lengkap</label>
							<textarea name="alamat" placeholder="alamat lengkap penerima..."><?php echo $alamat['lengkap'] ?> </textarea>
						  </div>
					</div>
					<div class="row">
						<div class="large-12 columns">
							<input class="button" type="submit" name="edit-alamat" value="Ubah Alamat"/>
						  </div>
					</div>
				</div>
				</form>
			</div>
		</div>
		<!-- Nav Sidebar -->
		<!-- This is source ordered to be pulled to the left on larger screens -->
		<?php view_tab($user); ?>
	  </div>
    <!-- End Content -->
<?php
	view_footer();
}
